package Demo;

/**
 * @author げっしょく
 * @date 2021/7/27
 */
public class KuaiPai {
    public static void main(String[] args) {
        int[] arr = {9, 6, 7, 8, 1, 6, 4, 2, 5, 3};
        kuaipai(arr,0,arr.length-1);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }

    public static void kuaipai(int[] arr , int left , int right ) {
        if (left > right) {
            return;
        }
        int a = arr[left];
        int left1 = left;
        int right1 = right;
        while (left1 != right1) {
            while (arr[right1] >= a && right1 > left1) {
                right1--;
            }
            while (arr[left1] <= a && right1 > left1) {
                left1++;
            }
            int tmp = arr[left1];
            arr[left1] = arr[right1];
            arr[right1] = tmp;
        }
        int tup = arr[left] ;
        arr[left] = arr[left1];
        arr[left1] = tup;
        kuaipai(arr,left,left1-1);
        kuaipai(arr,right1+1,right);

    }
}
